home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / userconf / shells.c < prev    next >
C/C++ Source or Header  |  1995-07-22  |  1KB  |  76 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. #include <sys/stat.h>
  6. #include "../paths.h"
  7. #include "../misc/misc.h"
  8. #include "userconf.h"
  9.  
  10. static char **tb;
  11. static int nb;
  12.  
  13. static void shells_read ()
  14. {
  15.     if (tb == NULL){
  16.         /* #Specification: userconf / /etc/shells & getusershell()
  17.             Shells available to configure user accounts are defined
  18.             by getusershell() (which reads /etc/shells optionnally).
  19.  
  20.             It is assumed that the first entry in /etc/shells is the default
  21.             shell (When the field is empty in /etc/passwd).
  22.         */
  23.         tb = (char**)malloc_err(100*sizeof(char*));
  24.         char *pt;
  25.         while ((pt=getusershell())!=NULL){
  26.                 tb[nb++] = strdup(pt);
  27.         }
  28.     }
  29. }
  30.  
  31. /*
  32.     Return != 0 if a path is an accepted shell
  33. */
  34. int shells_isok(const char *path)
  35. {
  36.     shells_read();
  37.     int ret = 0;
  38.     if (path[0] == '\0'){
  39.         ret = 1;
  40.     }else{
  41.         for (int i=0; i<nb; i++){
  42.             if (strcmp(tb[i],path)==0){
  43.                 ret = 1;
  44.                 break;
  45.             }
  46.         }
  47.     }
  48.     return ret;
  49. }
  50.  
  51. int shells_exist (const char *path)
  52. {
  53.     struct stat sstat;
  54.     int ret = 0;
  55.     if (path[0] == '\0'){
  56.         ret = 1;
  57.     }else{
  58.         if (stat(path,&sstat)!=-1
  59.             && S_ISREG(sstat.st_mode)
  60.             && sstat.st_mode & 1){
  61.             ret = 1;
  62.         }
  63.     }
  64.     return ret;
  65. }
  66.  
  67. /*
  68.     Return the path of the default shell for normal user.
  69. */
  70. const char *shells_getdefault()
  71. {
  72.     shells_read();
  73.     return tb[0];
  74. }
  75.  
  76.